package com.lzw.breezeNovel.webApp.service.impl.video;

import com.lzw.breezeNovel.model.entity.pojo.video.TvEpisode;
import com.lzw.breezeNovel.webApp.mapper.video.TvEpisodeMapper;
import com.lzw.breezeNovel.webApp.service.video.TvEpisodeService;
import com.lzw.breezeNovel.webApp.vo.video.TvEpisodeVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import static java.util.stream.Collectors.toList;

/**
 * @author 清风明月
 * @Package com.lzw.breezeNovel.webApp.service.impl.video
 * @date 2025/3/20
 * @description 电视剧的集数
 */
@Service
@SuppressWarnings("all")
public class TvEpisodeServiceImpl implements TvEpisodeService {

    /**
     * 注入mapper
     */
    @Autowired
    private TvEpisodeMapper tvEpisodeMapper;

    /**
     * 根据电视剧id查询集数
     *
     * @param id 电视剧id
     * @return 集数列表
     */
    @Override
    @Transactional(readOnly = true)
    public List<TvEpisodeVo> getTvEpisodeById(Integer id) {
        //根据id查询电视剧的集数
        List<TvEpisode> tvEpisodes = tvEpisodeMapper.getTvEpisodeById(id);
        //将集数列表转换为vo列表
        return tvEpisodes.stream().map(tv ->{
            TvEpisodeVo tvEpisodeVo = new TvEpisodeVo();
            BeanUtils.copyProperties(tv,tvEpisodeVo);
            return tvEpisodeVo;
        }).collect(toList());
    }
}
